﻿<Window x:Class="TicTacToe.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TicTacToe" Height="525" Width="525" MinHeight="100" MinWidth="100" Background="Gray" WindowStyle="None" ResizeMode="CanResizeWithGrip" WindowStartupLocation="CenterScreen">
    <StackPanel>
        <Grid x:Name="ButtonGrid" Background="Gray">
            <Menu Name="Main">
                <MenuItem Name="MainMenu" Header="_Main Menu">
                    <MenuItem Name="OnePlayerBtn" Header="_1 Player" Click="OnePlayerBtn_Click" />
                    <MenuItem Name="TwoPlayerBtn" Header="_2 Players" Click="TwoPlayerBtn_Click"/>
                    <MenuItem Name="ExitBtn" Header="E_xit" Click="ExitBtn_Click"/>
                </MenuItem>
                <MenuItem Name="NewGameBtn" Header="_New Game" Click="NewGameBtn_Click"/>
            </Menu>
            <TextBlock x:Name="TB_GameOver" Visibility="Hidden" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,5,0" Foreground="Maroon" FontSize="20" FontWeight="SemiBold" Height="25"/>
        </Grid>
        <Grid x:Name="MainGrid" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowGridLines="False">
            <Grid.Resources>
                <Style x:Key="CellBorderStyle" TargetType="Border">
                    <Setter Property="BorderBrush" Value="AliceBlue"/>
                    <Setter Property="BorderThickness" Value="1"/>
                    <Setter Property="Background" Value="Black"/>
                    <Setter Property="Height" Value="Auto"/>
                    <Setter Property="Width" Value="Auto"/>
                    <Setter Property="HorizontalAlignment" Value="Stretch"/>
                    <Setter Property="VerticalAlignment" Value="Stretch"/>
                </Style>

                <ControlTemplate x:Key="CellBorderTemplate" TargetType="{x:Type Control}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="OnLoaded1" RepeatBehavior="Forever">
                            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="theBorder" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                <SplineColorKeyFrame KeyTime="00:00:00" Value="#FFF4F712"/>
                                <SplineColorKeyFrame KeyTime="00:00:00.5" Value="#FFF4F712"/>
                                <SplineColorKeyFrame KeyTime="00:00:00.5000000" Value="#FF000000"/>
                                <SplineColorKeyFrame KeyTime="00:00:01" Value="#FF000000"/>
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Border x:Name="theBorder" Style="{StaticResource CellBorderStyle}" MouseLeftButtonDown="Border_MouseLeftButtonDown" />
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding IsBlinking}" Value="true">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource OnLoaded1}" x:Name="OnLoaded1_BeginStoryboard"/>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <StopStoryboard BeginStoryboardName="OnLoaded1_BeginStoryboard"/>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>

                <ControlTemplate x:Key="TheCircleTemplate" TargetType="{x:Type Control}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="OnLoaded1" RepeatBehavior="Forever">
                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                                <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="180"/>
                                <SplineDoubleKeyFrame KeyTime="00:00:01.2000000" Value="360"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Rectangle HorizontalAlignment="Center" VerticalAlignment="Center" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" RadiusX="{Binding RadiousXY}" RadiusY="{Binding RadiousXY}"  StrokeThickness="5" Fill="{x:Null}" RenderTransformOrigin="0.5,0.5" x:Name="rectangle">
                        <Rectangle.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform ScaleX="1" ScaleY="1"/>
                                <SkewTransform AngleX="0" AngleY="0"/>
                                <RotateTransform Angle="0"/>
                                <TranslateTransform X="0" Y="0"/>
                            </TransformGroup>
                        </Rectangle.RenderTransform>
                        <Rectangle.Stroke>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FF19FF00" Offset="0.053"/>
                                <GradientStop Color="#FFFF0083" Offset="0.078"/>
                            </LinearGradientBrush>
                        </Rectangle.Stroke>
                    </Rectangle>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding IsRotating}" Value="true">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource OnLoaded1}" x:Name="OnLoaded1_BeginStoryboard"/>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <StopStoryboard BeginStoryboardName="OnLoaded1_BeginStoryboard"/>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>

                <ControlTemplate x:Key="BlueCross" TargetType="Control">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="OnLoaded1" RepeatBehavior="Forever">
                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="R1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="45"/>
                                <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="225"/>
                                <SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="360"/>
                                <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="405"/>
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="R2" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="315"/>
                                <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="360"/>
                                <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="540"/>
                                <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="675"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Grid>
                        <Rectangle x:Name="R1" Height="5" Width="{TemplateBinding Width}" VerticalAlignment="Center" HorizontalAlignment="Center" Fill="#FFFF0083" RenderTransformOrigin="0.5,0.5">
                            <Rectangle.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform ScaleX="1" ScaleY="1"/>
                                    <SkewTransform AngleX="0" AngleY="0"/>
                                    <RotateTransform Angle="45"/>
                                    <TranslateTransform X="0" Y="0"/>
                                </TransformGroup>
                            </Rectangle.RenderTransform>
                        </Rectangle>
                        <Rectangle x:Name="R2" Height="5" Width="{TemplateBinding Width}" VerticalAlignment="Center" HorizontalAlignment="Center" Fill="#FF19FF00" RenderTransformOrigin="0.5,0.5">
                            <Rectangle.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform ScaleX="1" ScaleY="1"/>
                                    <SkewTransform AngleX="0" AngleY="0"/>
                                    <RotateTransform Angle="315"/>
                                    <TranslateTransform X="0" Y="0"/>
                                </TransformGroup>
                            </Rectangle.RenderTransform>
                        </Rectangle>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding IsRotating}" Value="true">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource OnLoaded1}" x:Name="OnLoaded1_BeginStoryboard"/>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <StopStoryboard BeginStoryboardName="OnLoaded1_BeginStoryboard"/>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Control x:Name="B1" Grid.Row="0" Grid.Column="0" Template="{StaticResource CellBorderTemplate}" />
            <Control x:Name="B2" Grid.Row="0" Grid.Column="1" MouseLeftButtonDown="Border_MouseLeftButtonDown" Template="{StaticResource CellBorderTemplate}" />
            <Control x:Name="B3" Grid.Row="0" Grid.Column="2" MouseLeftButtonDown="Border_MouseLeftButtonDown" Template="{StaticResource CellBorderTemplate}" />
            <Control x:Name="B4" Grid.Row="1" Grid.Column="0" MouseLeftButtonDown="Border_MouseLeftButtonDown" Template="{StaticResource CellBorderTemplate}" />
            <Control x:Name="B5" Grid.Row="1" Grid.Column="1" MouseLeftButtonDown="Border_MouseLeftButtonDown" Template="{StaticResource CellBorderTemplate}" />
            <Control x:Name="B6" Grid.Row="1" Grid.Column="2" MouseLeftButtonDown="Border_MouseLeftButtonDown" Template="{StaticResource CellBorderTemplate}" />
            <Control x:Name="B7" Grid.Row="2" Grid.Column="0" MouseLeftButtonDown="Border_MouseLeftButtonDown" Template="{StaticResource CellBorderTemplate}" />
            <Control x:Name="B8" Grid.Row="2" Grid.Column="1" MouseLeftButtonDown="Border_MouseLeftButtonDown" Template="{StaticResource CellBorderTemplate}" />
            <Control x:Name="B9" Grid.Row="2" Grid.Column="2" MouseLeftButtonDown="Border_MouseLeftButtonDown" Template="{StaticResource CellBorderTemplate}" />
        </Grid>
    </StackPanel>
</Window>
